﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace SMS
{
    public partial class uDanhsachtaikhoan : UserControl
    {
        fLogin main;

        public uDanhsachtaikhoan(fLogin main1)
        {
            InitializeComponent();
            main = main1;
        }
       private DataTable show()
        {
            SqlDataAdapter da;
            DataTable dt = new DataTable();
            SqlConnection con = main.KetNoiDB.GetConServer();
            try
            {
                da = new SqlDataAdapter("SELECT MATK as 'Mã Tài Khoản',TENTK as 'Tên Tài Khoản',MATKHAUMD as 'Mật Khẩu' FROM TAIKHOAN ", con);
                dt.Clear();
                da.Fill(dt); // do ket qua truy van vao ban
                
            }
           catch(Exception ex){
               MessageBox.Show("Lỗi!Xin thử lại" + ex.Message);
           }
            return dt;
        }
        private void dataGridView1_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            int selectRow = dataGridView1.CurrentRow.Index;
            string dataMaTK = dataGridView1.Rows[selectRow].Cells[0].Value.ToString();
            string dataTenTK = dataGridView1.Rows[selectRow].Cells[1].Value.ToString();
            string dataMatKhau = dataGridView1.Rows[selectRow].Cells[2].Value.ToString();
            main.ThongTinTaiKhoan.txtMaTK.Text = dataMaTK;
            main.ThongTinTaiKhoan.txtTenTK.Text = dataTenTK;
            main.ThongTinTaiKhoan.txtMatKhau.Text = dataMatKhau;
            main.ThongTinTaiKhoan.ShowDialog();
            

             
        }


        private void uDanhsachtaikhoan_Load(object sender, EventArgs e)
        {
            dataGridView1.DataSource = show();
        }
        public void updateDSTK()
        {
            dataGridView1.DataSource = show();
        }

    }
}
